home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1453.dms / var1453.adf / Lists / Example1.c < prev    next >
C/C++ Source or Header  |  1992-05-02  |  3KB  |  94 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM System                  Amiga C Club       */
  7. /* Chapter: Lists                       Tulevagen 22       */
  8. /* File:    Example1.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.00                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* Demonstrates how to create a list with three nodes. */
  21. /* (Not very amazing, but useful to know.)             */
  22.  
  23. #include <exec/types.h>
  24. #include <exec/lists.h> /* This file will automatically */
  25.                         /* include the file "nodes.h".  */
  26.  
  27. /* Declare a complete node stucture: */
  28. struct ToDo
  29. {
  30.   struct Node node; /* Every node must have this. */
  31.   STRPTR Wish;      /* Our own data.              */
  32. };
  33.  
  34.  
  35. /* Declare a list structure: */
  36. struct List my_list;
  37.  
  38.  
  39. /* Node 1: */
  40. struct ToDo eat=
  41. {
  42.   { NULL, NULL, NT_UNKNOWN, 0, "Food" },
  43.   "eat breakfast"
  44. };
  45.  
  46. /* Node 2: */
  47. struct ToDo sleep=
  48. {
  49.   { NULL, NULL, NT_UNKNOWN, 0, "Sleep" },
  50.   "rest"
  51. };
  52.  
  53. /* Node 3: */
  54. struct ToDo drink=
  55. {
  56.   { NULL, NULL, NT_UNKNOWN, 0, "Food" },
  57.   "drink some nice wine"
  58. };
  59.  
  60.  
  61. main()
  62. {
  63.   /* Initialize our list structure: */
  64.   NewList( &my_list );
  65.  
  66.  
  67.   /* Add three nodes: */
  68.   printf( "Adding some nodes...\n" );
  69.   AddTail( &my_list, &eat );
  70.   AddTail( &my_list, &sleep );
  71.   AddTail( &my_list, &drink );
  72.  
  73.  
  74.   /* Check if the list is empty or not: */
  75.   if( my_list.lh_Head->ln_Succ == NULL )
  76.     printf( "This list is empty!\n" );
  77.   else
  78.     printf( "There is one or more nodes in this list!\n" );
  79.  
  80.  
  81.   /* Remove all nodes from the list: */
  82.   printf( "Remove all nodes...\n" );
  83.   RemHead( &my_list, &eat );
  84.   RemHead( &my_list, &sleep );
  85.   RemHead( &my_list, &drink );
  86.   /* Note! Actually you do not remove the nodes before your  */
  87.   /* program terminates, but it looks a bit nicer if you do. */
  88.   /* (If you have allocated memory for the nodes while your  */
  89.   /* program was running you must of course deallocate it,   */
  90.   /* and before you do that the nodes should have been       */
  91.   /* removed.)                                               */
  92. }
  93.  
  94.